/**
 * XQuery to Scala Translator
 * Fatemeh Borran-Dejnabadi
 * 26 December 2004
 */

package xquery2src;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;

/** A small test class for the translator of xquey;
 *
 *  usage: scala xquery2src.TranslatorTest <file.xq>
 */
object TranslatorTest extends Translator {
  def main(args:Array[String]) = {
    Console.println("********** TranslatorTest **********");
    try {
      in = new FileInputStream(args.apply(0));
      val outname:String =  args.apply(0).substring(6, args.apply(0).indexOf(".xq"));
      val out:PrintWriter = new PrintWriter(new FileOutputStream("Tests\\" + outname + ".scala"));
      nextCh();
      nextToken();
      val tree:Tree = parse();
      close();
      analyze(tree);
      tree.translation.append("package result;\n\n");
      tree.translation.append("import scala.xml._;\n");
      tree.translation.append("import xquery2src.Lib._;\n\n");
      tree.translation.append("object " + outname + " extends Application {\n");
      tree.translation.append("   val result = ");
      translate(tree);
      tree.translation.append(";\n   Console.println(result);\n}\n");
      out.write(tree.translation.toString());
      out.flush();
      System.out.println(tree.translation);
    } catch {
      case e:IOException =>
	Report.fail(e.getMessage());
    }
  }
}
